package dukeCE.InsightTracker;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CheckableItemAdapter extends BaseAdapter {

    private final List<CheckableItem> items;
    
    public CheckableItemAdapter(final Context context, final int itemResId,
            final List<CheckableItem> items)
    {
        this.items = items;
    }

    public int getCount() {
        return this.items.size();
    }

    public Object getItem(int position) {
        return this.items.get(position);
    }

    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	
    	final CheckableItem item = this.items.get(position);
        View itemView = null;
        LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        itemView = inflater.inflate(R.layout.row, null);


        // Set the text of the item
        TextView topicTxt = (TextView) itemView.findViewById(R.id.topicTxt);
        TextView desTxt =(TextView) itemView.findViewById(R.id.descriptionTxt);
        topicTxt.setText(item.getName());
        desTxt.setText(item.getDes());
        

        // Set the check-icon
        ImageView imgViewChecked = (ImageView) itemView.findViewById(R.id.checked_icon);
        if(item.isChecked())
        	imgViewChecked.setImageResource(R.drawable.star_icon);
        return itemView;

    }
}